<?php

require_once '../mysqlConnect.php'; //mysqli database connect

function getQuestionnaireNames()
{
	$conn = GetConnection();
	$sql = "SELECT * FROM Questionnaire";
	$value = $conn->query($sql);
	return $value;	
	$conn->close();	
}
function getSectionInfobySessionQid ()
{
	$conn = GetConnection();
	$sql = "SELECT * FROM Section S WHERE S.QID = '$_SESSION[Qid]'";
	$value = $conn->query($sql);
	return $value;	
	$conn->close();
}
function getQInfofromQTitle ($Qtitle)
{
	$conn = GetConnection();
	$sql = "SELECT * FROM Questionnaire Q WHERE Q.Title = '$Qtitle'";
	$value = $conn->query($sql);
	$rs = $value->fetch_assoc();
	return $rs;
	$conn->close();
}
function getAdminInfofromQTitle ($Qtitle)
{
	$Qinfo = getQInfofromQTitle ($Qtitle);
	$id = $Qinfo['ID'];
	$conn = GetConnection();
	$sql = "SELECT AID FROM Edit E WHERE E.QID = '$id'";
	$value1 = $conn->query($sql);
	$rs1 = $value1->fetch_assoc();
	$aid = $rs1['AID'];
	$sql = "SELECT * FROM Administrator A WHERE A.ID = '$aid'";
	$value2 = $conn->query($sql);
	$rs2 = $value2->fetch_assoc();
	return $rs2;
	$conn->close();
}
function setSessionQidbyQTitle ($Qtitle)
{
	$Qinfo = getQInfofromQTitle ($Qtitle);
	$id = $Qinfo['ID'];
	$_SESSION['Qid'] = $id;
}
function getSectionInfobyID ($id)
{
	$conn = GetConnection();
	$sql = "SELECT * FROM Section S WHERE S.ID = '$id'";
	$value = $conn->query($sql);
	$rs = $value->fetch_assoc();
	return $rs;	
	$conn->close();
}
function createSectionArray ($Sectioninfo)
{
	setSectionArrayCount (0);
	$_SESSION['SectionNumArray'] = null;
	$_SESSION['SectionNumArray'] = array();
	while ($rs2 = $Sectioninfo->fetch_assoc()) :
		array_push($_SESSION['SectionNumArray'], $rs2['ID']);  //creates an array with section numbers and fills it
	endwhile;
	$_SESSION['arraySize'] = count($_SESSION['SectionNumArray']) - 1;			
}
function setSectionArrayCount ($num)
{
	$_SESSION['SectionArrayCount'] = $num;
}
function getSectionArrayCount ()
{
	return $_SESSION['SectionArrayCount'];
}
function getSectionNumberfromArray ($arrayIndex)
{
	//return $_SESSION['SectionNumArray'][getSectionArrayCount()];
	return $_SESSION['SectionNumArray'][$arrayIndex];
}
function getPatientNames()
{
	$conn = GetConnection();
	$sql = "SELECT * FROM Patient ORDER BY LName";
	$value = $conn->query($sql);
	return $value;	
	$conn->close();
}
function getMedicationNames()
{
	$conn = GetConnection();
	$sql = "SELECT * FROM Medication";
	$value = $conn->query($sql);
	return $value;	
	$conn->close();
}
function getPatientInfobyID($id)
{
	$conn = GetConnection();
	$sql = "SELECT * FROM Patient WHERE ID ='$id'";
	$value = $conn->query($sql);
	$rs = $value->fetch_assoc();
	return $rs;	
	$conn->close();
}
?>